<template>
  <div class="recommended-articles">
    <!-- 装饰元素 -->
    <div class="card-decorations">
      <div class="decoration-star star-1"></div>
      <div class="decoration-star star-2"></div>
      <div class="decoration-star star-3"></div>
    </div>
    <div class="card-header">
      <el-icon class="header-icon"><Star /></el-icon>
      <h3 class="header-title">推荐文章</h3>
      <div class="header-line"></div>
    </div>

    <div class="article-list">
      <router-link
          v-for="(article, index) in articleList?.slice(0, 8)"
          :key="index"
          class="article-item"
          :class="{ 'top-3': index < 3 }"
          :to="'/articles/' + article.id"
      >
        <div class="rank-number" :style="{ backgroundColor: getRankColor(index) }">
          {{ index + 1 }}
        </div>
        <div class="article-cover">
          <el-image fit="cover" :src="article.coverImage"></el-image>
        </div>
        <div class="article-info">
          <div class="article-title">{{ article.title }}</div>
          <div class="article-meta">
            <el-icon><Calendar /></el-icon>
            <span>{{ article.createTime?.toString().split(' ')[0] }}</span>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Star, Calendar } from '@element-plus/icons-vue'
import {onMounted, toRefs} from "vue";

const articles = [
  {
    title: '2024年前端开发趋势展望：新技术与最佳实践',
    views: '2.3k'
  },
  {
    title: 'Vue3 Composition API 实战指南',
    views: '1.8k'
  },
  {
    title: 'TypeScript 高级特性详解',
    views: '1.5k'
  },
  {
    title: '前端性能优化的20个小技巧',
    views: '1.2k'
  },
  {
    title: '深入理解 Vue3 响应式原理',
    views: '1.1k'
  }
]

const getRankColor = (index: number): string => {
  const colors = [
    '#ff6b81',  // 粉红色 - 第1名
    '#ff92a5',  // 浅粉色 - 第2名
    '#ffb8c9',  // 更浅的粉色 - 第3名
    '#a8e6cf',  // 浅绿色 - 第4名
    '#88d8c0',  // 青绿色 - 第5名
    '#78c2ad',  // 深青绿 - 第6名
    '#74b9ff',  // 浅蓝色 - 第7名
    '#81ecec'   // 浅青色 - 第8名
  ]
  return colors[index] || colors[colors.length - 1]
}

const props = defineProps(['articleList']);

const {articleList} =toRefs(props)
</script>

<style scoped lang="scss">
@import '@/assets/styles/variables.scss';

.recommended-articles {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 25px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(227, 242, 253, 0.3);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--gradient-purple);
    transition: height 0.3s ease;
  }
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  }
  
  &:hover::before {
    height: 6px;
  }
}

.card-decorations {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.decoration-star {
  position: absolute;
  font-size: 12px;
  color: rgba(108, 92, 231, 0.3);
  animation: starTwinkle 3s ease-in-out infinite;
  
  &::before {
    content: '★';
  }
}

.star-1 {
  top: 20px;
  right: 20px;
  animation-delay: 0s;
}

.star-2 {
  top: 60px;
  right: 35px;
  font-size: 8px;
  animation-delay: 1s;
}

.star-3 {
  bottom: 40px;
  left: 20px;
  font-size: 10px;
  animation-delay: 2s;
}


@keyframes starTwinkle {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.3) rotate(180deg);
    opacity: 0.8;
  }
}


.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  gap: 10px;
  position: relative;
  z-index: 2;
}

.header-line {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--bg-decoration), transparent);
  margin-left: 15px;
  border-radius: 2px;
  animation: headerPulse 2s ease-in-out infinite;
}

@keyframes headerPulse {
  0%, 100% {
    opacity: 0.4;
    transform: scaleX(1);
  }
  50% {
    opacity: 0.8;
    transform: scaleX(1.1);
  }
}

.header-icon {
  font-size: 1.6rem;
  color: #6c5ce7;
  animation: star-shine 2s infinite;
}

@keyframes star-shine {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
}

.header-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.article-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px;
  border-radius: 12px;
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  min-height: 80px;
}

.article-cover {
  width: 70px;
  height: 52px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.article-cover .el-image {
  width: 100%;
  height: 100%;
}

.article-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 105, 180, 0.1),
      transparent
  );
  transition: 0.5s;
}

.article-item:hover::before {
  left: 100%;
}

.article-item:hover {
  background: rgba(255, 105, 180, 0.05);
  transform: translateX(5px);
}

.rank-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 2px;
}

.article-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.article-title {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.4;
  transition: color 0.3s;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-item:hover .article-title {
  color: var(--primary-color);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.article-meta .el-icon {
  font-size: 1rem;
}

.top-3 {
  background: rgba(255, 105, 180, 0.05);
}

.top-3 .article-title {
  font-weight: 500;
}

/* Animation for new items */
.article-item {
  animation: slide-in 0.5s ease-out forwards;
  opacity: 0;
  transform: translateY(20px);
}

@keyframes slide-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .article-title {
    font-size: 0.85rem;
  }
}
</style>
